package com.bit.frige;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

import com.bit.frige.DB.DBContactHelper;
import com.bit.frige.DB.FoodDTO;
import com.bit.frige.sub.food.SubFoodContensActivity;
import com.bit.frige.sub.food.SubFoodEditFormActivity;


public class MainFoodActivity extends Activity {
	Button btn1, btn2, btn4;
	GridView grid;
	
	//추가 START 2014년 1월 7일 ryu
	DBContactHelper db;
	ArrayList<FoodDTO> foodlist;
	String[] arr;
	@SuppressWarnings("unused")
	private ArrayAdapter<String> adapter;
	@SuppressWarnings("unused")
	private TextView status;
	//추가 END 2014년 1월 7일 ryu
	
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_food);

//		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//		  ActionBar actionBar = getActionBar();
//	        actionBar.hide();
		
		btn1 = (Button) findViewById(R.id.button2);
		btn2 = (Button) findViewById(R.id.button1);
        
        //유통기한 순으로 데이터를 표시할 그리드 뷰 생성 부분        
		db = new DBContactHelper(this);
		foodlist = db.getAllUserInfo();
		ArrayList<FoodDTO> list2= new ArrayList<FoodDTO>();
		
        grid = (GridView)findViewById(R.id.grid);
        final ImageAdapter adapter = new ImageAdapter(this, foodlist);
        grid.setAdapter(adapter);
        
	// 그리드뷰 클릭 이벤트-->윤성이가 식품정보화면 만들면 그쪽으로 연결할 것
        grid.setOnItemClickListener(new OnItemClickListener() {
        	   public void onItemClick(AdapterView<?> parent, View v,
        			     int position, long id) {
        		   Intent intent = new Intent(MainFoodActivity.this, SubFoodEditFormActivity.class);
        		   intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        		   intent.putExtra("id",foodlist.get(position).getId());
        		   startActivity(intent);
        			   }
        			  }); 

        
        
		//냉장
		btn1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),TabtestActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				intent.putExtra("place", 2);
				startActivity(intent);
			}
		});
		//냉동
		btn2.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getApplicationContext(),TabtestActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				intent.putExtra("place", 1);
				startActivity(intent);
			}
		});
	}


}


